<?php

namespace app\admin\model\card;

use app\admin\model\Admin;
use think\Model;


class Apps extends Model
{

    // 表名
    protected $name = 'apps';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];


    protected function idsStringToArray($ids) {
        return explode(',', $ids);
    }


    public function getAdminsAttr($value,$data)
    {
        $ids = explode(',', $data['admin_ids']);

        $admins = [];
        foreach ($ids as $id) {
            $admin = \model('\app\admin\model\Admin')->where('id', $id)->field(['id', 'username'])->find();
            if ($admin) {
                $admins[] = $admin;
            }
        }

        return $admins;
    }
}
